﻿namespace Tanmia.Basis.Prism
{
    using System;
    using System.Windows;
    using System.Windows.Input;

    public class BaseWindow : Window
    {
        #region Private Fields
        private double height;
        private double width;
        private double top;
        private double left;
        #endregion

        public BaseWindow()
        {
            AddHandler(LoadedEvent, new RoutedEventHandler(OnWindowLoaded));
        }

        protected virtual void OnWindowLoaded(object sender, RoutedEventArgs e)
        {
            height = this.ActualHeight;
            width = this.ActualWidth;
            top = this.Top;
            left = this.Left;
        }

        protected FrameworkElement GetControl(object original)
        {
            if (original == null)
                throw new ArgumentNullException("original");

            if (original as FrameworkElement == null)
                throw new InvalidOperationException("An original control is not FrameworkElement.");

            return original as FrameworkElement;
        }

        protected virtual void NormalizeWindow()
        {
            this.Height = height;
            this.Width = width;
            this.Top = top;
            this.Left = left;

            WindowState = WindowState.Normal;
        }

        protected virtual void MaximizeWindow()
        {
            WindowState = System.Windows.WindowState.Maximized;
        }

        protected virtual void MinimizeWindow()
        {
            WindowState = System.Windows.WindowState.Minimized;
        }

        protected virtual void DraggingWindow(MouseButtonEventArgs e)
        {
            if (e.ChangedButton == MouseButton.Left)
                DragMove();
        }
    }
}